package com.exhibition.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.exhibition.service.ITbSampleInfoService;
import com.exhibition.service.ITbSampleTypeService;
import com.exhibition.util.Util;

@Controller
public class TbSampleInfoController {
	
	@Autowired
	ITbSampleInfoService tbSampleInfoService;
	@Autowired
	ITbSampleTypeService tbSampleTypeService;
	
	@RequestMapping("unit/sampleInfoList.do")	
	public ModelAndView list(HttpServletRequest request,String ehi_id){
		ModelAndView mav=new ModelAndView("./sampleinfo/list.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("exh_id", ehi_id);
		map.put("unit_id", request.getSession().getAttribute("unit_id"));
		mav.addObject("list", tbSampleInfoService.getList(map));
		mav.addObject("ehi_id", ehi_id);
		return mav;
	}
	@RequestMapping("unit/sampleInfoAdd.do")	
	public ModelAndView sampleInfoAdd(HttpServletRequest request,String exh_id){
		ModelAndView mav=new ModelAndView("./sampleinfo/add.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		mav.addObject("list", tbSampleTypeService.getList(map));
		mav.addObject("exh_id", exh_id);
		return mav;
	}
	@RequestMapping("unit/sampleInfoAddOk.do")
	public ModelAndView addOk(HttpServletRequest request,
			  String exh_id,
			  String unit_id,
			  String type_id,
			  String exh_name,
			  String exh_model,
			  String exh_spe,
			  String exh_count,
			  String exh_price,
			  String exh_send,
			  String exh_in_time,
			  String exh_end_time,
			  String exh_remark){
		ModelAndView mav=new ModelAndView("redirect:/unit/unitInviteList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("sam_id", Util.getPrimaryKey());
		map.put("exh_id", exh_id);
		map.put("unit_id", request.getSession().getAttribute("unit_id"));
		map.put("type_id", type_id);
		map.put("exh_name", exh_name);
		map.put("exh_model", exh_model);
		map.put("exh_spe", exh_spe);
		map.put("exh_count", exh_count);
		map.put("exh_price", exh_price);
		map.put("exh_send", exh_send);
		map.put("exh_in_time", exh_in_time);
		map.put("exh_end_time", exh_end_time);
		map.put("exh_remark", exh_remark);
		tbSampleInfoService.add(map);
		return mav;
	}
	@RequestMapping("unit/sampleInfoDelete.do")	
	public ModelAndView deleteSam(HttpServletRequest request,String sam_id){
		ModelAndView mav=new ModelAndView("redirect:/unit/unitInviteList.do");
		tbSampleInfoService.delete(sam_id);
		return mav;
	}
	@RequestMapping("host/sampleInfoAdd.do")	
	public ModelAndView exhinfoUpdate(HttpServletRequest request){
		ModelAndView mav=new ModelAndView("./exhinfo/update.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		mav.addObject("list", tbSampleTypeService.getList(map));
		return mav;
	}
//	@RequestMapping("host/sampleInfoAddOk.do")
//	public ModelAndView addOk(HttpServletRequest request,
//			  String sam_id,
//			  String exh_id,
//			  String unit_id,
//			  String type_id,
//			  String exh_name,
//			  String exh_model,
//			  String exh_spe,
//			  String exh_count,
//			  String exh_price,
//			  String exh_send,
//			  String exh_in_time,
//			  String exh_end_time,
//			  String exh_remark){
//		ModelAndView mav=new ModelAndView("redirect:/admin/unitList.do");
//		Map<String,Object> map=new HashMap<String,Object>();
//		map.put("sam_id", Util.getPrimaryKey());
//		map.put("exh_id", unit_account);
//		map.put("unit_id", unit_pwd);
//		map.put("unit_name", unit_name);
//		map.put("unit_address", unit_address);
//		map.put("unit_size", unit_size);
//		map.put("unit_industry", unit_industry);
//		map.put("unit_nature", unit_nature);
//		tbUnitService.add(map);
//		return mav;
//	}
	@RequestMapping("host/sampleInfoUpdate.do")	
	public ModelAndView update(HttpServletRequest request,String unit_id){
		ModelAndView mav=new ModelAndView("./unit/update.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("unit_id", unit_id);
		mav.addObject("unit", tbSampleInfoService.getOne(map));
		return mav;
	}
	@RequestMapping("host/sampleInfoUpdateOk.do")	
	public ModelAndView updateOk(HttpServletRequest request,
			String unit_id,
			String unit_account,
			String unit_pwd,
			String unit_name,
			String unit_address,
			String unit_size,
			String unit_industry,
			String unit_nature
			){
		ModelAndView mav=new ModelAndView("redirect:/admin/unitList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("unit_id", unit_id);
		map.put("unit_account", unit_account);
		map.put("unit_pwd", unit_pwd);
		map.put("unit_name", unit_name);
		map.put("unit_address", unit_address);
		map.put("unit_size", unit_size);
		map.put("unit_industry", unit_industry);
		map.put("unit_nature", unit_nature);
		tbSampleInfoService.update(map);
		return mav;
	}
	@RequestMapping("host/sampleInfoDelete.do")	
	public ModelAndView delete(HttpServletRequest request,String unit_id){
		ModelAndView mav=new ModelAndView("redirect:/admin/unitList.do");
		tbSampleInfoService.delete(unit_id);
		return mav;
	}
}
